package leetcode.code0423;

import java.util.HashMap;
import java.util.Map;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

public class Solution1 implements IDebug {
	// one two three four five six seven eight nine zero
	// two four six eight zero
	// w u x g z
	// one three five seven nine
	// o t f s i
	public String originalDigits(String s) {
		Map<Character, Integer> map = new HashMap<>();
		for (char c : s.toCharArray()) {
			int num = map.getOrDefault(c, 0);
			map.put(c, num + 1);
		}
		int[] nums = new int[10];
		nums[2] = map.getOrDefault('w', 0);
		nums[4] = map.getOrDefault('u', 0);
		nums[6] = map.getOrDefault('x', 0);
		nums[8] = map.getOrDefault('g', 0);
		nums[0] = map.getOrDefault('z', 0);
		nums[3] = map.getOrDefault('t', 0) - nums[2] - nums[8];
		nums[1] = map.getOrDefault('o', 0) - nums[0] - nums[2] - nums[4];
		nums[5] = map.getOrDefault('f', 0) - nums[4];
		nums[7] = map.getOrDefault('s', 0) - nums[6];
		nums[9] = map.getOrDefault('i', 0) - nums[5] - nums[6] - nums[8];
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < 10; i++) {
			int num = nums[i];
			while (num > 0) {
				sb.append(i);
				num--;
			}
		}
		return sb.toString();
	}

	@Override
	public void debug1() {
		String s = "owoztneoer";
		String r = this.originalDigits(s);
		String e = "012";
		HelpDebug.compare(e, r);

	}

	@Override
	public void debug2() {
		String s = "fviefuro";
		String r = this.originalDigits(s);
		String e = "45";
		HelpDebug.compare(e, r);

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution1 so = new Solution1();
		so.debug1();
		so.debug2();
	}

}
